package com.xxgc.eow.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xxgc.eow.entity.Postask;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.xxgc.eow.result.Result;

import java.time.LocalDateTime;
import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.xxgc.eow.service.IPostskillService;
import com.xxgc.eow.entity.Postskill;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 职位技能表 前端控制器
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-23
 */
@Tag(name = "职位技能表")
@RestController
@RequestMapping("/postskill")
public class PostskillController {

    @Resource
    private IPostskillService postskillService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "查询所有接口", description = "查询职位技能表所有数据")
    @SaIgnore
    @GetMapping
    public Result<List<Postskill>> findAll() {
        return Result.ok(postskillService.getALl());
    }

    /**
     * 根据id查询数据接口
     * @param postId
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "根据postId查询数据接口", description = "通过postId查询")
    @Parameters({
            @Parameter(name = "postId",description = "postId",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/{postId}")
    public Result<List<Postskill>> findOne(@PathVariable Integer postId) {
        return Result.ok(postskillService.getALlByPostId(postId));
    }
//
//    /**
//     * 分页查询接口
//     * @param pageNum
//     * @param pageSize
//     * @return
//     */
//    @ApiOperationSupport(author = "Mr.Abel")
//    @Operation(summary = "分页查询接口", description = "分页查询")
//    @Parameters({
//            @Parameter(name = "pageNum",description = "页码",example="1",required = true,in=ParameterIn.QUERY),
//            @Parameter(name = "pageSize",description = "每页多少条",example="10",required = true,in=ParameterIn.QUERY)
//    })
//    @SaIgnore
//    @GetMapping("/page")
//    public Result<Page<Postskill>> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
//        QueryWrapper<Postskill> queryWrapper = new QueryWrapper<>();
//        return Result.ok(postskillService.page(new Page<>(pageNum, pageSize), queryWrapper));
//    }

    /**
     * 新增接口
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "新增接口", description = "新增接口")
    @SaIgnore
    @PostMapping("/save")
    public Result save(@RequestBody Postskill postskill) {
        if (postskill.getCreateTime() == null){
            postskill.setCreateTime(LocalDateTime.now());
        }
        postskillService.addPostSkill(postskill);
        return Result.ok();
    }
    /**
     * 更新接口
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "更新接口", description = "根据旧的SkillId 和 postId 更新")
    @SaIgnore
    @PostMapping("/update")
    public Result update(@RequestBody Postskill postskill,int oldSkillId) {
        postskillService.updatPostSkill(postskill,oldSkillId);
        return Result.ok();
    }

    /**
     * 删除接口
     * @param PostId
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "删除接口", description = "通过PostId 和skillId 删除")
    @Parameters({
            @Parameter(name = "PostId",description = "PostId",required = true,in=ParameterIn.QUERY),
            @Parameter(name = "skillId",description = "skillId",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/del")
    public Result delete(@Parameter Integer PostId , @Parameter int skillId) {
        Postskill postskill = new Postskill();
        postskill.setPostId(PostId);
        postskill.setSkillId(skillId);
        postskill.setDestroyTime(LocalDateTime.now());
        postskill.setTip(1);
        postskillService.delPostSkill(postskill);
        return Result.ok();
    }

//    /**
//     * 批量删除接口
//     * @param ids
//     * @return
//     */
//    @ApiOperationSupport(author = "Mr.Abel")
//    @Operation(summary = "批量删除接口", description = "批量删除接口")
//    @SaIgnore
//    @PostMapping("/del/batch")
//    public Result deleteBatch(@RequestBody List<Integer> ids) {
//        postskillService.removeByIds(ids);
//        return Result.ok();
//    }
}